<?php
/**
 * 添加马甲
 */
require_once dirname(__DIR__)."/common.php";
use app\cls\tom\SysResource;
use app\cls\tom\Tools;
use app\model\Users;

$db =  SysResource::getDB(true);
$userModel = new Users($db);
$userModel->setDb($db);
$userDir = __DIR__."/mj_user/";
ob_start();
passthru("ls {$userDir} 2>&1");
$files = ob_get_clean();
$files = explode("\n",$files);
$files = array_filter($files);
$a=["7号球衣","130trbl","alisa","ara洛","island","jeanine","jimmylee","kaka","katherine","k神我们做朋友吧","lotusily","monster","moran","pablohoney"
    ,"supersheep","tomorrow","verkhovtsev","yinna","yola","zoey","白小鹿","彬蔚","钵西里尼","不冯","哆啦dora","放学别跑","风继续吹","关西包"
    ,"好好学习天天向上","喝咖啡的猫","黑雪公主","黄宇斌","可笑却无公主病","罗凯云","罗纳尔烦","铝合金","麻酱","马丁路德_慢","派大星","潘帕斯的培根","皮格芹"
    ,"七楼","枪花","肉酱意粉","食唔食菠萝包","士多啤梨苹果橙","是我头发不够多么","汤太咸了","王嘉禹","旺福","竹林半夏"];
foreach($files as $k=>$file){
    $fullFile = $userDir.$file;
//    $nickname = pathinfo($fullFile,PATHINFO_FILENAME);
    $nickname = $a[$k];

    $filePath = CDN_PATH."/head_image5/host_mj/";
    if(!file_exists($filePath)){
        exec("mkdir -p {$filePath} && chown www.www {$filePath}");
    }
    $newFile = $filePath.md5($file).".jpg";
    if(file_exists($newFile)){
        echo "---{$file}已经存在,跳过-----\n";
        continue;
    }
    exec("cp $fullFile $newFile");
    if(!file_exists($newFile)){
        echo "---{$file}拷贝失败,跳过-----\n";
        continue;
    }
    $data = [
        "uuid"=>Tools::UUID(),
        "third_uuid"=>"host_".Tools::UUID(),
        "nick_name"=>$nickname,
        "nick_pic"=>str_replace(CDN_PATH,CDN_HOST,$newFile),
        "user_type"=>2,
        "add_time"=>date("Y-m-d H:i:s"),
    ];
    $db->insert("users",$data);
    $userId = $db->insert_id();
    echo "---【id:{$userId}】---【{$nickname}】添加成功-----休眠一秒----.\n";
    sleep(1);//睡眠秒 防止UUID重复
}